﻿#include "AnimationUtil.h"

Animation * AnimationUtil::getPlistFile(std::string plistFile, std::string plistPng, std::string pngName,float delay, int iLoops){
	auto frameCache = SpriteFrameCache::getInstance();
	frameCache->addSpriteFramesWithFile(plistFile, plistPng);

	SpriteFrame* frame = NULL;
	Vector<SpriteFrame*>frameVec;

	int index = 1;
	do
	{
		std::string strName = StringUtils::format("%s_%02d.png", pngName.c_str(), index);
		frame = frameCache->getSpriteFrameByName(StringUtils::format("%s_%02d.png", pngName.c_str(), index));
		index++;
		if (frame == nullptr)
			break;
		frameVec.pushBack(frame);
	} while (true);

	Animation * animation = Animation::createWithSpriteFrames(frameVec,delay,iLoops);
	animation->setRestoreOriginalFrame(true);
	AnimationCache::getInstance()->addAnimation(animation, pngName);
	return animation;
}